<script setup lang="ts">
import { ref, watch } from 'vue'

const checked = ref(false)
const changeChecked = () => {
  checked.value = false
}
watch(checked, () => {
  checked.value
    ? window.addEventListener('click', changeChecked)
    : window.removeEventListener('click', changeChecked)
})
</script>
<template>
  <nav class="menu">
    <input type="checkbox" class="menu-toggler" id="menu_toggler" v-model="checked" />
    <label for="menu_toggler"></label>
    <ul>
      <li class="menu-item" title="首页">
        <RouterLink to="/"><i class="vxe-icon-home"></i></RouterLink>
      </li>
      <li class="menu-item" title="数据查询">
        <RouterLink to="/crud"><i class="vxe-icon-table"></i></RouterLink>
      </li>
      <li class="menu-item" title="大屏展示">
        <RouterLink to="/echarts"><i class="vxe-icon-chart-bar-y"></i></RouterLink>
      </li>
    </ul>
  </nav>
</template>
<style scoped>
.menu-toggler {
  position: absolute;
  display: block;
  top: 10px;
  right: 10px;
  margin: auto;
  width: 40px;
  height: 40px;
  z-index: 11;
  opacity: 0;
  cursor: pointer;
}
.menu-toggler:hover + label,
.menu-toggler:hover + label::before,
.menu-toggler:hover + label::after {
  background: rgba(246, 0, 0, 0.9);
}
.menu-toggler:checked + label {
  background: transparent;
}
.menu-toggler:checked + label::before,
.menu-toggler:checked + label::after {
  top: 0;
  width: 40px;
  transform-origin: 50% 50%;
}
.menu-toggler:checked + label::before {
  transform: rotate(45deg);
}
.menu-toggler:checked + label::after {
  transform: rotate(-45deg);
}
.menu-toggler:checked ~ ul .menu-item {
  opacity: 1;
}
.menu-toggler:checked ~ ul .menu-item:nth-child(1) {
  transform: rotate(-30deg) translateX(-110px);
}
.menu-toggler:checked ~ ul .menu-item:nth-child(2) {
  transform: rotate(90deg) translateX(-110px);
}
.menu-toggler:checked ~ ul .menu-item:nth-child(3) {
  transform: rotate(210deg) translateX(-110px);
}
.menu-toggler:checked ~ ul .menu-item a {
  pointer-events: auto;
}
.menu-toggler + label {
  width: 40px;
  height: 5px;
  display: block;
  z-index: 11;
  border-radius: 2.5px;
  background: rgba(246, 0, 0, 0.7);
  transition: transform 0.5s, top 0.5s;
  position: absolute;
  top: 27.5px;
  right: 10px;
  margin: auto;
}
.menu-toggler + label::before,
.menu-toggler + label::after {
  width: 40px;
  height: 5px;
  display: block;
  z-index: 11;
  border-radius: 2.5px;
  background: rgba(246, 0, 0, 0.7);
  transition: transform 0.5s, top 0.5s;
  content: '';
  position: absolute;
  left: 0;
}
.menu-toggler + label::before {
  top: 15px;
}
.menu-toggler + label::after {
  top: -15px;
}
.menu-item:nth-child(1) a {
  transform: rotate(30deg);
}
.menu-item:nth-child(2) a {
  transform: rotate(-90deg);
}
.menu-item:nth-child(3) a {
  transform: rotate(-210deg);
}
.menu-item {
  position: absolute;
  display: block;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 80px;
  height: 80px;
  opacity: 0;
  transition: 0.5s;
  z-index: 11;
}
.menu-item a {
  display: block;
  width: inherit;
  height: inherit;
  line-height: 80px;
  color: rgba(0, 255, 187, 0.7);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  text-align: center;
  text-decoration: none;
  font-size: 40px;
  pointer-events: none;
  transition: 0.2s;
}
.menu-item a:hover {
  box-shadow: 0 0 0 2px rgba(0, 255, 110, 0.3);
  color: rgba(0, 255, 110, 0.3);
  background: rgba(0, 0, 0, 0.5);
  font-size: 45px;
}
</style>
